package com.sky.web.app;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.xml.crypto.Data;

@RestController
@Slf4j
@RequestMapping("/user/order")
public class AppOrderController {
    @Autowired
    private OrderService orderService;

    @PostMapping("submit")
    public Result OrderSubmit(@RequestBody OrdersSubmitDTO dto){
       OrderSubmitVO vo = orderService.OrderSubmit(dto);

        return Result.success(vo);
    }

    // 订单支付
    @PutMapping("/payment")
    public Result<OrderPaymentVO> payment(@RequestBody OrdersPaymentDTO ordersPaymentDTO) throws Exception {
        log.info("订单支付：{}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.payment(ordersPaymentDTO);
        log.info("生成预支付交易单：{}", orderPaymentVO);
        return Result.success(orderPaymentVO);
    }

    @GetMapping("historyOrders")
    public Result historyOrders(OrdersPageQueryDTO dto){
       PageResult pageResult = orderService.historyOrders(dto);

        return Result.success(pageResult);
    }

    @GetMapping("orderDetail/{id}")
    public Result findById(@PathVariable Long id){
       OrderVO vo = orderService.findById(id);

        return Result.success(vo);
    }

    @PutMapping("cancel/{id}")
    public Result orderCancel(@PathVariable Long id){
        orderService.orderCancel(id);

        return Result.success();
    }

    @PostMapping("repetition/{id}")
    public Result repetition(@PathVariable Long id){
        orderService.repetition(id);

        return Result.success();
    }

    @GetMapping("/reminder/{id}")
    public Result reminder(@PathVariable Long id){
        orderService.reminder(id);

        return Result.success();
    }
}
